<template>
  <common-dialog :dialogVisible="dialogVisible" :showClose="false" width="520px" :title="'项目任务催办'" @cancel="cancel" @ok="ok">
    <div class="urged-wrappery">
      <div class="urged">
        <span><span class="required">*</span>催办方式：</span>
        <a-radio-group v-model="value">
          <a-radio :value="1">飞书</a-radio>
          <a-radio :value="2">邮件</a-radio>
        </a-radio-group>
      </div>
      <div class="urged">
        <span><span class="required">*</span>催办描述：</span>
        <a-textarea
          v-model="urgedDesc"
          placeholder="请输入内容"
          :auto-size="{ minRows: 5, maxRows: 7 }"
        />
      </div>
    </div>
  </common-dialog>
</template>
<script>
import commonDialog from '@/components/common/commonDialog'
import { noticeUser } from '@/api/projectPlan'
let userinfo = JSON.parse(sessionStorage.getItem('userInfo'))
export default {
  components: { commonDialog },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    // 催办任务oid
    urgedTaskOid: {
      type: Array,
      default: function() {
        return []
      }
    }
  },
  data() {
    return {
      value: 1, // 1 飞书  2 邮件
      urgedDesc: '请尽快完成此项目任务。', // 催办描述
    }
  },
  watch: {
    dialogVisible() {
      this.value = 1
      this.urgedDesc = '请尽快完成此项目任务。'
    }
  },
  methods: {
    cancel() {
      this.$emit('cancel')
    },
    ok() {
      if (!this.urgedDesc) {
        this.$message.info('请输入催办描述')
      } else {
        let params = {
          "userId": userinfo.loginName,
          "oids": this.urgedTaskOid,
          "email": this.value === 2,
          "feishu": this.value === 1,
          "title": "",
          "link":"",
          "content": this.urgedDesc
        }
        this.$emit('ok')
        let msg = `${this.value === 1 ? '飞书' : '邮件'}通知成功`
        noticeUser(params).then(({data}) => {
          if (!data.success) {
            this.$message.error(data.message || '操作失败')
          } else {
            this.$message.success(msg)
          }
        }).catch(err => {
          console.log(err)
        })
      }
    }
  }
}
</script>
<style lang="less" scoped>
  .urged-wrappery{
    .urged{
      display: flex;
      > span {
        margin-right: 10px;
        min-width: 85px;
      }
      &:nth-of-type(1) {
        margin-bottom: 21px;
      }
      .required{
        color: red;
        margin-right: 5px;
      }
    }
  }
</style>